<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />








  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.2" />






<meta name="description" content="帮助命令  whatis      简要的说明命令 info        详细的说明命令 man         查询命令的说明文档 which       查询程序binary文件所在的目录 whereis     查询程序的搜索路径   在linux终端，面对命令不知道怎么用，或不记得命令的拼写及参数时，我们需要求助于系统的帮助文档； linux系统内置的帮助文档很详细，通常能解决我们的问题">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux基本命令">
<meta property="og:url" content="http://xiezixi.oschina.io/2018/05/15/linux基本命令/index.html">
<meta property="og:site_name" content="个人博客">
<meta property="og:description" content="帮助命令  whatis      简要的说明命令 info        详细的说明命令 man         查询命令的说明文档 which       查询程序binary文件所在的目录 whereis     查询程序的搜索路径   在linux终端，面对命令不知道怎么用，或不记得命令的拼写及参数时，我们需要求助于系统的帮助文档； linux系统内置的帮助文档很详细，通常能解决我们的问题">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-05-15T11:52:50.719Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux基本命令">
<meta name="twitter:description" content="帮助命令  whatis      简要的说明命令 info        详细的说明命令 man         查询命令的说明文档 which       查询程序binary文件所在的目录 whereis     查询程序的搜索路径   在linux终端，面对命令不知道怎么用，或不记得命令的拼写及参数时，我们需要求助于系统的帮助文档； linux系统内置的帮助文档很详细，通常能解决我们的问题">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://xiezixi.oschina.io/2018/05/15/linux基本命令/"/>





  <title>Linux基本命令 | 个人博客</title>
  














</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">个人博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">曦瓜皮</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>


 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://xiezixi.oschina.io/blog/2018/05/15/linux基本命令/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="曦瓜皮">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="个人博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Linux基本命令</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-05-15T19:52:50+08:00">
                2018-05-15
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Linux/" itemprop="url" rel="index">
                    <span itemprop="name">Linux</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="帮助命令"><a href="#帮助命令" class="headerlink" title="帮助命令"></a>帮助命令</h2><blockquote>
<ol>
<li><strong>whatis</strong>      <em>简要的说明命令</em></li>
<li><strong>info</strong>        <em>详细的说明命令</em></li>
<li><strong>man</strong>         <em>查询命令的说明文档</em></li>
<li><strong>which</strong>       <em>查询程序binary文件所在的目录</em></li>
<li><strong>whereis</strong>     <em>查询程序的搜索路径</em></li>
</ol>
</blockquote>
<p>在linux终端，面对命令不知道怎么用，或不记得命令的拼写及参数时，我们需要求助于系统的帮助文档； linux系统内置的帮助文档很详细，通常能解决我们的问题，我们需要掌握如何正确的去使用它们；</p>
<blockquote>
<ul>
<li>在只记得部分命令关键字的场合，我们可通过man -k来搜索；</li>
<li>需要知道某个命令的简要说明，可以使用whatis；而更详细的介绍，则可用info命令；</li>
<li>查看命令在哪个位置，我们需要使用which；</li>
<li>而对于命令的具体参数及使用方法，我们需要用到强大的man。</li>
</ul>
</blockquote>
<h3 id="查询命令"><a href="#查询命令" class="headerlink" title="查询命令"></a>查询命令</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">whatis <span class="built_in">command</span>    <span class="comment"># 查询命令的简要说明</span></span><br><span class="line">info <span class="built_in">command</span>      <span class="comment"># 查询命令的详细说明</span></span><br><span class="line">man <span class="built_in">command</span>       <span class="comment"># 查询命令的说明文档</span></span><br></pre></td></tr></table></figure>
<h3 id="查看路径"><a href="#查看路径" class="headerlink" title="查看路径"></a>查看路径</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">which</span> <span class="built_in">command</span>     <span class="comment"># 查看程序的binary文件所在路径</span></span><br><span class="line">whereis <span class="built_in">command</span>   <span class="comment"># 查看程序的搜索路径</span></span><br></pre></td></tr></table></figure>
<h2 id="文件及目录管理"><a href="#文件及目录管理" class="headerlink" title="文件及目录管理"></a>文件及目录管理</h2><blockquote>
<ol>
<li><strong>mkdir</strong>                  <em>创建目录</em></li>
<li><strong>rm</strong>                     <em>删除</em></li>
<li><strong>mv</strong>                     <em>移动或更名文件</em></li>
<li><strong>cp</strong>                     <em>复制文件</em></li>
<li><strong>cd</strong>                     <em>目录切换</em></li>
<li><strong>pwd</strong>                    <em>显示当前路径</em></li>
<li><strong>ls</strong>                     <em>列出目录项</em></li>
<li><strong>find/locate</strong>            <em>查找目录或文件</em></li>
<li><strong>updatedb</strong>               <em>更新索引库</em></li>
<li><strong>cat/vi/head/tail/more</strong> <em>查看文件内容</em></li>
<li><strong>diff</strong>                  <em>查看两个文件间的差别</em></li>
<li><strong>egrep/grep</strong>            <em>查找文件内容</em></li>
<li><strong>chown</strong>                 <em>修改文件拥有者</em></li>
<li><strong>chmod</strong>                 <em>修改文件权限</em></li>
<li><strong>ln</strong>                    <em>增加别名</em></li>
<li><strong>|</strong>                     <em>批处理命令连接执行</em></li>
<li><strong>;</strong>                     <em>串联</em></li>
<li><strong>&amp;&amp;</strong>                    <em>前面成功，则执行后面一条，否则，不执行</em></li>
<li><strong>||</strong>                    <em>前面失败，则后一条执行</em></li>
<li><strong>.profile</strong>              <em>设置环境变量</em></li>
</ol>
</blockquote>
<p>文件管理不外乎文件或目录的创建、删除、查询、移动，有mkdir/rm/mv；文件查询是重点，用find来进行查询；find的参数丰富，也非常强大；有时候，需要给文件创建一个别名，我们需要用到ln，使用这个别名和使用原文件是相同的效果。</p>
<h3 id="创建、删除、查询、移动"><a href="#创建、删除、查询、移动" class="headerlink" title="创建、删除、查询、移动"></a>创建、删除、查询、移动</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">mkdir       <span class="comment"># 创建目录</span></span><br><span class="line">rm          <span class="comment"># 删除文件或目录(-rf 删除非空目录)</span></span><br><span class="line">mv          <span class="comment"># 移动/重命名文件</span></span><br><span class="line">cp          <span class="comment"># 复制</span></span><br><span class="line">find        <span class="comment"># 查询</span></span><br></pre></td></tr></table></figure>
<h3 id="目录切换"><a href="#目录切换" class="headerlink" title="目录切换"></a>目录切换</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span>          <span class="comment"># 找到文件/目录位置</span></span><br><span class="line"><span class="built_in">cd</span> -        <span class="comment"># 切换到上一个工作目录</span></span><br><span class="line"><span class="built_in">cd</span> or <span class="built_in">cd</span> ~  <span class="comment"># 切换到home目录</span></span><br><span class="line"><span class="built_in">pwd</span>         <span class="comment"># 显示当前路径</span></span><br></pre></td></tr></table></figure>
<h3 id="列出目录项"><a href="#列出目录项" class="headerlink" title="列出目录项"></a>列出目录项</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">ls          <span class="comment"># 显示当前目录下的文件，目录</span></span><br><span class="line">ls -lrt     <span class="comment"># 按时间排序，列表的形式显示目录项</span></span><br><span class="line">ls | cat -n <span class="comment"># 给文件添加id编号</span></span><br><span class="line">ls -al | more   <span class="comment"># 按页显示列表内容</span></span><br></pre></td></tr></table></figure>
<p>在.bashrc 中设置命令别名，.bashrc 在/home/你的用户名/ 文件夹下，以隐藏文件的方式存储；可使用 ls -a 查看。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">alias</span> lsl=<span class="string">'ls -lrt'</span></span><br><span class="line"><span class="built_in">alias</span> lm=<span class="string">'ls -al|more'</span></span><br></pre></td></tr></table></figure>
<h3 id="查找目录及文件"><a href="#查找目录及文件" class="headerlink" title="查找目录及文件"></a>查找目录及文件</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">find ./ -name <span class="string">"tomcat*"</span> | xargs file    <span class="comment"># 查询文件或目录</span></span><br><span class="line">find ./ -name <span class="string">'*.txt'</span>                   <span class="comment"># 查询是否含有txt文件</span></span><br><span class="line">locate string                           <span class="comment"># 查询所有包含string的路径</span></span><br></pre></td></tr></table></figure>
<p>find是实时查找，如果需要更快的查询，可试试locate；locate会为文件系统建立索引数据库，如果有文件更新，需要定期执行更新命令来更新索引库:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">updatedb</span><br></pre></td></tr></table></figure>
<h3 id="查看文件内容"><a href="#查看文件内容" class="headerlink" title="查看文件内容"></a>查看文件内容</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">cat -n file         <span class="comment"># 显示时同时显示行号</span></span><br><span class="line">head -10 file       <span class="comment"># 显示前10行</span></span><br><span class="line">tail -10 file       <span class="comment"># 显示后10行</span></span><br><span class="line">diff file1 file2    <span class="comment"># 查看两个文件的差别</span></span><br><span class="line">tail -f file        <span class="comment"># 动态显示文本最新信息(查看日志信息)</span></span><br></pre></td></tr></table></figure>
<h3 id="查找文件内容"><a href="#查找文件内容" class="headerlink" title="查找文件内容"></a>查找文件内容</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">egrep <span class="string">'03.1\/CO\/AE'</span> TSF_STAT_111130.log.012</span><br><span class="line">egrep <span class="string">'A_LMCA777:C'</span> TSF_STAT_111130.log.035 &gt; co.out2</span><br></pre></td></tr></table></figure>
<h3 id="修改文件与目录权限"><a href="#修改文件与目录权限" class="headerlink" title="*修改文件与目录权限"></a>*修改文件与目录权限</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">chown                       <span class="comment"># 改变文件的拥有者</span></span><br><span class="line">chmod                       <span class="comment"># 改变文件读、写、执行等属性</span></span><br><span class="line">chown -R tuxapp <span class="built_in">source</span>/     <span class="comment"># 递归子目录修改</span></span><br><span class="line">chmod a+x myscript          <span class="comment"># 增加脚本可执行权限</span></span><br></pre></td></tr></table></figure>
<h3 id="给文件增加别名"><a href="#给文件增加别名" class="headerlink" title="给文件增加别名"></a>给文件增加别名</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ln cc ccAgain   <span class="comment"># 硬连接；删除一个，将仍能找到；</span></span><br><span class="line">ln -s cc ccTo   <span class="comment"># 符号链接(软链接)；删除源，另一个无法使用；（后面一个ccTo 为新建的文件）</span></span><br></pre></td></tr></table></figure>
<h3 id="管道和重定向"><a href="#管道和重定向" class="headerlink" title="管道和重定向"></a>管道和重定向</h3><blockquote>
<ul>
<li>批处理命令连接执行，使用 |</li>
<li>串联: 使用分号 ;</li>
<li>前面成功，则执行后面一条，否则，不执行：&amp;&amp;</li>
<li>前面失败，则后一条执行: ||</li>
</ul>
</blockquote>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">ls /proc &amp;&amp; <span class="built_in">echo</span>  suss! || <span class="built_in">echo</span> failed.         <span class="comment"># 能够提示命名是否执行成功or失败</span></span><br><span class="line"><span class="keyword">if</span> ls /proc; <span class="keyword">then</span> <span class="built_in">echo</span> suss; <span class="keyword">else</span> <span class="built_in">echo</span> fail; <span class="keyword">fi</span> <span class="comment"># 与上述效果相同</span></span><br><span class="line">:&gt; a.txt                                        <span class="comment"># 清空文件</span></span><br><span class="line"><span class="built_in">echo</span> aa &gt;&gt; a.txt                                <span class="comment"># 重定向</span></span><br></pre></td></tr></table></figure>
<h3 id="设置环境变量"><a href="#设置环境变量" class="headerlink" title="设置环境变量"></a>设置环境变量</h3><p>启动帐号后自动执行的是 文件为 .profile，然后通过这个文件可设置自己的环境变量；<br>安装的软件路径一般需要加入到path中：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">PATH=<span class="variable">$APPDIR</span>:/opt/app/soft/bin:<span class="variable">$PATH</span>:/usr/<span class="built_in">local</span>/bin:<span class="variable">$TUXDIR</span>/bin:<span class="variable">$ORACLE_HOME</span>/bin;<span class="built_in">export</span> PATH</span><br></pre></td></tr></table></figure>
<h3 id="Bash快捷输入或删除"><a href="#Bash快捷输入或删除" class="headerlink" title="Bash快捷输入或删除"></a>Bash快捷输入或删除</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Ctl-U   删除光标到行首的所有字符,在某些设置下,删除全行</span><br><span class="line">Ctl-W   删除当前光标到前边的最近一个空格之间的字符</span><br><span class="line">Ctl-H   backspace,删除光标前边的字符</span><br><span class="line">Ctl-R   匹配最相近的一个文件，然后输出</span><br></pre></td></tr></table></figure>
<h3 id="综合应用"><a href="#综合应用" class="headerlink" title="综合应用"></a>综合应用</h3><p>查找record.log中包含AAA，但不包含BBB的记录的总数:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat -v record.log | grep AAA | grep -v BBB | wc -l</span><br></pre></td></tr></table></figure>
<h2 id="网络工具"><a href="#网络工具" class="headerlink" title="网络工具"></a>网络工具</h2><h3 id="查询网络服务和端口"><a href="#查询网络服务和端口" class="headerlink" title="查询网络服务和端口"></a>查询网络服务和端口</h3><h2 id="用户管理工具"><a href="#用户管理工具" class="headerlink" title="用户管理工具"></a>用户管理工具</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">useradd                 <span class="comment"># 添加用户</span></span><br><span class="line">passwd                  <span class="comment"># 为用户设置密码</span></span><br><span class="line">userdel                 <span class="comment"># 删除用户</span></span><br><span class="line">su                      <span class="comment"># 账号切换</span></span><br><span class="line">groups                  <span class="comment"># 查看当前用户所属的组</span></span><br><span class="line">usermod                 <span class="comment"># 修改用户所属的组</span></span><br><span class="line">chmod                   <span class="comment"># 更改读写权限</span></span><br><span class="line">chown                   <span class="comment"># 更改文件或目录的拥有者</span></span><br><span class="line">.bashrc/.bash_profile   <span class="comment"># 环境变量</span></span><br></pre></td></tr></table></figure>
<h3 id="用户"><a href="#用户" class="headerlink" title="用户"></a>用户</h3><h4 id="添加用户"><a href="#添加用户" class="headerlink" title="添加用户"></a>添加用户</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">useradd -m username         <span class="comment"># 该命令为用户创建相应的帐号和用户目录/home/username</span></span><br><span class="line">passwd username             <span class="comment"># 密码以交互方式创建</span></span><br></pre></td></tr></table></figure>
<h4 id="删除用户"><a href="#删除用户" class="headerlink" title="删除用户"></a>删除用户</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">userdel -r username         <span class="comment"># 删除用户</span></span><br><span class="line">su userB                    <span class="comment"># 帐号切换</span></span><br></pre></td></tr></table></figure>
<h3 id="用户的组"><a href="#用户的组" class="headerlink" title="用户的组"></a>用户的组</h3><h4 id="将用户加入到组"><a href="#将用户加入到组" class="headerlink" title="将用户加入到组"></a>将用户加入到组</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">groups                          <span class="comment"># 查看当前用户所属的组</span></span><br><span class="line">usermod -G groupNmame username  <span class="comment"># 将用户加入到组</span></span><br><span class="line">usermod -g groupName username   <span class="comment"># 变更用户所属的组</span></span><br></pre></td></tr></table></figure>
<h4 id="查看系统所有的组"><a href="#查看系统所有的组" class="headerlink" title="查看系统所有的组"></a>查看系统所有的组</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">more /etc/passwd        <span class="comment"># 查看所有用户及权限</span></span><br><span class="line">more /etc/group         <span class="comment"># 查看所有的用户组及权限</span></span><br></pre></td></tr></table></figure>
<h3 id="用户权限"><a href="#用户权限" class="headerlink" title="用户权限"></a>用户权限</h3><h4 id="更改读写权限"><a href="#更改读写权限" class="headerlink" title="更改读写权限"></a>更改读写权限</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">chmod userMark(+|-)PermissionsMark  <span class="comment"># 更改读写权限</span></span><br><span class="line"><span class="comment"># userMark取值：(u：用户，g：组，o：其它用户，a：所有用户)</span></span><br><span class="line"><span class="comment"># PermissionsMark取值：(r:读，w：写，x：执行)</span></span><br><span class="line"><span class="comment"># 例如：</span></span><br><span class="line">chmod a+x main      <span class="comment"># 对所有用户给文件main增加可执行权限</span></span><br><span class="line">chmod g+w blogs     <span class="comment"># 对组用户给文件blogs增加可写权限</span></span><br></pre></td></tr></table></figure>
<h4 id="更改文件或目录的拥有者"><a href="#更改文件或目录的拥有者" class="headerlink" title="更改文件或目录的拥有者"></a>更改文件或目录的拥有者</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chown username dirOrFile    <span class="comment"># 更改文件或目录的拥有者</span></span><br></pre></td></tr></table></figure>
<h3 id="环境变量"><a href="#环境变量" class="headerlink" title="环境变量"></a>环境变量</h3><p>/etc/profile，/etc/bashrc 是系统全局环境变量设定<br>~/.profile，~/.bashrc用户目录下的私有环境变量设定</p>
<h2 id="系统管理及IPC资源管理"><a href="#系统管理及IPC资源管理" class="headerlink" title="系统管理及IPC资源管理"></a>系统管理及IPC资源管理</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 汇总</span></span><br><span class="line">uname/lsb_release       <span class="comment"># 查看Linux系统版本(Linux Standard Base)</span></span><br><span class="line">sar                     <span class="comment"># 查看(System Activity Reporter)</span></span><br><span class="line">arch                    <span class="comment"># 显示架构(Autoregressive conditional heteroskedasticity model)</span></span><br><span class="line">date                    <span class="comment"># 查看设置系统时间</span></span><br><span class="line">clock                   <span class="comment"># 强制把系统时间写入CMOS</span></span><br><span class="line">tzselect                <span class="comment"># 选择时区</span></span><br><span class="line">ipcs                    <span class="comment"># IPC资源查询(Inter-Process Communication)</span></span><br><span class="line"><span class="built_in">ulimit</span>                  <span class="comment"># 检测和设置系统资源限制</span></span><br></pre></td></tr></table></figure>
<h3 id="系统管理"><a href="#系统管理" class="headerlink" title="系统管理"></a>系统管理</h3><h4 id="查询系统版本"><a href="#查询系统版本" class="headerlink" title="查询系统版本"></a>查询系统版本</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">uname -a            <span class="comment"># 查看Linux系统版本</span></span><br><span class="line">lsb_release -a      <span class="comment"># 查看Linux系统版本</span></span><br><span class="line">more /etc/release   <span class="comment"># 查看Unix系统版本</span></span><br></pre></td></tr></table></figure>
<h4 id="查询硬件信息"><a href="#查询硬件信息" class="headerlink" title="查询硬件信息"></a>查询硬件信息</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">sar -u 5 10                                 <span class="comment"># 查看CPU使用情况</span></span><br><span class="line">cat /proc/cpuinfo                           <span class="comment"># 查询CPU信息</span></span><br><span class="line">cat /proc/cpuinfo | grep processor | wc -l  <span class="comment"># 查看CPU的核的个数</span></span><br><span class="line">cat /proc/meminfo                           <span class="comment"># 查看内存信息</span></span><br><span class="line">pagesize                                    <span class="comment"># 显示内存page大小（以KByte为单位）</span></span><br><span class="line">arch                                        <span class="comment"># 显示架构</span></span><br></pre></td></tr></table></figure>
<h4 id="设置系统时间"><a href="#设置系统时间" class="headerlink" title="设置系统时间"></a>设置系统时间</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">date                            <span class="comment"># 显示当前系统时间</span></span><br><span class="line">date -s 2014-09-15 17:05:00     <span class="comment"># 设置系统日期和时间</span></span><br><span class="line">tzselect                        <span class="comment"># 设置时区</span></span><br><span class="line">clock -w                        <span class="comment"># 强制把系统时间写入CMOS</span></span><br><span class="line">date +%Y%m%d.%H%M%S             <span class="comment"># 格式化输出当前日期时间</span></span><br></pre></td></tr></table></figure>
<h3 id="IPC资源管理"><a href="#IPC资源管理" class="headerlink" title="IPC资源管理"></a>IPC资源管理</h3><h4 id="IPC资源查询"><a href="#IPC资源查询" class="headerlink" title="IPC资源查询"></a>IPC资源查询</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ipcs                    <span class="comment"># 查看系统使用的IPC资源</span></span><br><span class="line"><span class="built_in">ulimit</span>                  <span class="comment"># 检测和设置系统资源限制</span></span><br><span class="line"><span class="built_in">ulimit</span> –c unlimited     <span class="comment"># 对生成的 core 文件的大小不进行限制</span></span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/05/16/微信登录/" rel="prev" title="微信扫码登录">
                微信扫码登录 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/blog/images/avatar.jpg"
               alt="曦瓜皮" />
          <p class="site-author-name" itemprop="name">曦瓜皮</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/blog/archives/">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/blog/categories/index.html">
                <span class="site-state-item-count">6</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        

      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#帮助命令"><span class="nav-number">1.</span> <span class="nav-text">帮助命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#查询命令"><span class="nav-number">1.1.</span> <span class="nav-text">查询命令</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查看路径"><span class="nav-number">1.2.</span> <span class="nav-text">查看路径</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#文件及目录管理"><span class="nav-number">2.</span> <span class="nav-text">文件及目录管理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建、删除、查询、移动"><span class="nav-number">2.1.</span> <span class="nav-text">创建、删除、查询、移动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#目录切换"><span class="nav-number">2.2.</span> <span class="nav-text">目录切换</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#列出目录项"><span class="nav-number">2.3.</span> <span class="nav-text">列出目录项</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查找目录及文件"><span class="nav-number">2.4.</span> <span class="nav-text">查找目录及文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查看文件内容"><span class="nav-number">2.5.</span> <span class="nav-text">查看文件内容</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查找文件内容"><span class="nav-number">2.6.</span> <span class="nav-text">查找文件内容</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改文件与目录权限"><span class="nav-number">2.7.</span> <span class="nav-text">*修改文件与目录权限</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#给文件增加别名"><span class="nav-number">2.8.</span> <span class="nav-text">给文件增加别名</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#管道和重定向"><span class="nav-number">2.9.</span> <span class="nav-text">管道和重定向</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#设置环境变量"><span class="nav-number">2.10.</span> <span class="nav-text">设置环境变量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Bash快捷输入或删除"><span class="nav-number">2.11.</span> <span class="nav-text">Bash快捷输入或删除</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#综合应用"><span class="nav-number">2.12.</span> <span class="nav-text">综合应用</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#网络工具"><span class="nav-number">3.</span> <span class="nav-text">网络工具</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#查询网络服务和端口"><span class="nav-number">3.1.</span> <span class="nav-text">查询网络服务和端口</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#用户管理工具"><span class="nav-number">4.</span> <span class="nav-text">用户管理工具</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#用户"><span class="nav-number">4.1.</span> <span class="nav-text">用户</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#添加用户"><span class="nav-number">4.1.1.</span> <span class="nav-text">添加用户</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#删除用户"><span class="nav-number">4.1.2.</span> <span class="nav-text">删除用户</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#用户的组"><span class="nav-number">4.2.</span> <span class="nav-text">用户的组</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#将用户加入到组"><span class="nav-number">4.2.1.</span> <span class="nav-text">将用户加入到组</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#查看系统所有的组"><span class="nav-number">4.2.2.</span> <span class="nav-text">查看系统所有的组</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#用户权限"><span class="nav-number">4.3.</span> <span class="nav-text">用户权限</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#更改读写权限"><span class="nav-number">4.3.1.</span> <span class="nav-text">更改读写权限</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#更改文件或目录的拥有者"><span class="nav-number">4.3.2.</span> <span class="nav-text">更改文件或目录的拥有者</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#环境变量"><span class="nav-number">4.4.</span> <span class="nav-text">环境变量</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#系统管理及IPC资源管理"><span class="nav-number">5.</span> <span class="nav-text">系统管理及IPC资源管理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#系统管理"><span class="nav-number">5.1.</span> <span class="nav-text">系统管理</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#查询系统版本"><span class="nav-number">5.1.1.</span> <span class="nav-text">查询系统版本</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#查询硬件信息"><span class="nav-number">5.1.2.</span> <span class="nav-text">查询硬件信息</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#设置系统时间"><span class="nav-number">5.1.3.</span> <span class="nav-text">设置系统时间</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#IPC资源管理"><span class="nav-number">5.2.</span> <span class="nav-text">IPC资源管理</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#IPC资源查询"><span class="nav-number">5.2.1.</span> <span class="nav-text">IPC资源查询</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">曦瓜皮</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.2"></script>



  
  

  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  






  





  

  

  

  

  

  

</body>
</html>
